/* Basket class */
package nguyenquangminh.minigame;

import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.awt.event.MouseMotionListener;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;

public class Basket {
	private BufferedImage image;
	private static final int Y = 480;
	protected static final int WIDTH = 80;
	protected static final int HEIGHT = 70;
	private int x = 0;
	private int dx = 0;
	private Game game;
	
	// Constructor
	public Basket() {
		URL imageUrl = this.getClass().getResource("/images/Ro.png");
		try {
			image = ImageIO.read(imageUrl);
		} catch (IOException e) {
			e.printStackTrace();
		}
		x = 340;
		
	}
	// Move function
	public void move() {
		if ((x + dx > 0) && (x + dx < game.S_WIDTH-WIDTH)) 
			x = x + dx;
	}
	// Get X coordinates
	public int getX() {
		return x;
	}
	// Get Y coordinates
	public int getY() {
		return Y;
	}
	// Get Image
	public Image getImage() {
		return image;
	}
	// Key released event
	public void keyReleased(KeyEvent e) {
		dx = 0;
	}
	// Key pressed event
	public void keyPressed(KeyEvent e) {
		int key = e.getKeyCode();
		if (key == KeyEvent.VK_LEFT)
			dx = -1;
		if (key == KeyEvent.VK_RIGHT)
			dx = 1;
	}
	// Mouse moved event
	public void mouseMoved(MouseEvent e) {
		x = e.getX();
	}
	
	// Paint Basket
	public void paint(Graphics2D g2d) {
		g2d.drawImage(image, x, Y, WIDTH, HEIGHT, null);
	}
	
	// Rectangle basket
	public Rectangle getBounds() {
		return new Rectangle(x, Y, WIDTH, HEIGHT);
	}
}
